package com.kefu.smartCall.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kefu.common.controller.AbstractBaseController;
import com.kefu.common.result.Result;
import com.kefu.common.result.ResultGenerator;
import com.kefu.common.util.Assert;
import com.kefu.smartCall.model.ScTask;
import com.kefu.smartCall.service.ScTaskCallService;
import com.kefu.smartCall.service.ScTaskService;
import com.kefu.smartCall.vo.ScTaskSearchVo;
import com.kefu.smartCall.vo.ScTaskUpdateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "大模型任务")
@RestController
@RequestMapping("smartCall/task")
public class ScTaskController extends AbstractBaseController {
    @Resource
    protected ScTaskService scTaskService;

    @PostMapping("/list")
    @ApiOperation("大模型任务列表")
    public Result<Page<ScTask>> list(@Validated @RequestBody ScTaskSearchVo search) {
        Page<ScTask> page = scTaskService.searchLambdaPage(search);
        return ResultGenerator.genSuccessResult(page);
    }


    @PostMapping("/update")
    @ApiOperation("修改大模型筛选状态")
    public Result<String> update(@Validated @RequestBody ScTaskUpdateVo update) {
        ScTask scTask = scTaskService.findById(update.getTaskId());
        Assert.isNull(scTask, "大模型任务已被删除！");
        ScTask info = update.convert();
        scTaskService.updateById(info);
        return ResultGenerator.genSuccessResult();
    }
}
